var sdk = {};
// sdk.baseIP = 'http://33k931m051.wicp.vip/';
// sdk.companyIp = 'http://33k931m051.wicp.vip/';
// 
//sdk.baseIP = 'http://192.168.2.249:9198/';
//sdk.companyIp = 'http://192.168.2.249:9198/';
sdk.baseIP = 'https://www.zbifc.com/';
sdk.companyIp = 'https://www.zbifc.com/';
//sdk.companyIp = 'http://192.168.2.193:7788/';
//sdk.temporaryIp = 'http://192.168.2.193:9198/';
// sdk.baseIP = 'http://222.184.233.54:1008/jrcs/';
// sdk.companyIp = 'http://222.184.233.54:1008/jrcs/';
// 获取URL中的参数
sdk.getURLVar = function(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    return r != null ? decodeURI(r[2]) : null;
};
sdk.setURLVar = function(url, key, value) {
    if (url) {
        var urlList = url.split("#");
        var params = {};
        var query = urlList[0].split("?")[1];
        var result = urlList[0].split("?")[0] + "?";
        if (query) {
            query = query.split("&");
            for (var i in query) {
                var vars = query[i].split("=");
                params[vars[0]] = vars[1];
            }
        }
        if (value) {
            params[key] = value;
        } else {
            params[key] = null;
            delete params[key];
        }
        var first = true;
        for (var i in params) {
            result += ((first ? "" : "&") + i + "=" + (params[i] ? params[i] : ""));
            first = false;
        }
        return result + (urlList[1] ? ("#" + urlList[1]) : "");
    }
    return "";
};

// base64加密
sdk.setBase64 = function(input) {
    var str = $.base64.encode(input, 'utf-8');
    return str
}

// RSA加密
sdk.setEncrypt = function(publicKey, data) {
    var encrypt = new JSEncrypt.JSEncrypt();
    encrypt.setPublicKey(publicKey);
    return encrypt.encrypt(data);
};
// 获取机构列表
sdk.getJgData = function(data) {
    $.ajax({
        type: 'post',
        data: data,
        url: sdk.baseIP + '/mh/app/v2/jrjg/getNewJrjgPage',
        dataType: 'json',
        success: function(data) {
            var total = data.total;
            var Arr = data.rows;
            var p = {}
            for (var i = 1; i <= parseInt(total / 15 + 1); i++) {
                p['s' + i] = sdk.setPageNation(15, i, Arr);
                $('#ckvpbe' + i).html($.templates('#ckvpbeTmpl').render(p['s' + i]));
            }
        }
    });
}
//数组分页效果
sdk.setPageNation = function pagination(pageSize, currentPage, arr) {
    var skipNum = (currentPage - 1) * pageSize; //跳过的数量
    var newArr = (skipNum + pageSize >= arr.length) ? arr.slice(skipNum, arr.length) : arr.slice(skipNum, skipNum +
        pageSize);
    return newArr;
}

//格式化时间
 sdk.timeFormat = function(timestamp, format) {
  const formateArr = ['Y', 'M', 'D', 'h', 'm', 's'];
  const formatNumber = n => {
      n = n.toString()
      return n[1] ? n : '0' + n
  }
  
  let returnArr = [];
  let date = new Date(timestamp);
  //console.log('date',date)
  let year = date.getFullYear()
  let month = date.getMonth() + 1
  let day = date.getDate()
  let hour = date.getHours()
  let minute = date.getMinutes()
  let second = date.getSeconds()
  returnArr.push(year, month, day, hour, minute, second);
  returnArr = returnArr.map(formatNumber);
  for (var i in returnArr) {
      format = format.replace(formateArr[i], returnArr[i]);
  }
  return format;
}

// 1=>银行用户, 2 =>担保公司用户, 3 =>政府用户, 4=>企业用户, 5=>个人用户,88=>中国人民银行
// 990=>人行/银监,991=>乡镇街道
var totalUmby = {
    '1': {
        product: [{
            fildid: '3',
            name: '定向需求',
            badgeKey: 'dxxqCount',
            href: sdk.baseIP + 'zxw/jrjg/bankDbsx/dxqyxq'
        }, {
            fildid: '4',
            name: '非定向需求',
            badgeKey: 'fdxxqCount',
            href: sdk.baseIP + 'zxw/jrjg/bankDbsx/fdxqyxq'
        }],
        badge: {
            isNeed: true,
            requestMethod: 'post',
            href: sdk.baseIP + 'zxw/jrjg/bankDbsx/getCountNum'
        },
        fbadge: {
            isNeed: true,
            requestMethod: 'post',
            href: sdk.baseIP + 'zxw/jrjg/bankDbsx/getCountNum'
        }
    },
    '2': {
        product: [{
            fildid: '3',
            name: '担保审批',
            badgeKey: 'dspdbrwCount',
            href: sdk.baseIP + 'zxw/jrjg/dbgsDbsx/auditList'
        }],
        badge: {
            isNeed: true,
            requestMethod: 'post',
            href: sdk.baseIP + 'zxw/jrjg/bankDbsx/getCountNum'
        }
    },
    '3': {
        product: [{
            fildid: '3',
            name: '注册审核',
            badgeKey: 'sp',
            href: sdk.baseIP + 'zxw/gov/app/qyzhcsp?tname=qyzcsp'
        }, {
            fildid: '5',
            name: '我要撮合',
            badgeKey: 'ch',
            href: sdk.baseIP + 'zxw/gov/app/dchsx?tname=ddxqjg'
        }, {
            fildid: '6',
            name: '投诉管理',
            badgeKey: 'ts',
            href: sdk.baseIP + 'zxw/gov/app/tscl?tname=tscl'
        }, {
            fildid: '7',
            name: '统计分析',
            badgeKey: '',
            href: sdk.baseIP + 'zxw/gov/app/rzxq_zc?tname=zctj'
        }],
        badge: {
            isNeed: true,
            requestMethod: 'get',
            href: sdk.baseIP + 'zxw/gov/app/xqbaseinfo/getDbInfo'
        }
    },
    '4': {
        product: [{
            fildid: '1',
            name: '我要贷款',
            href: sdk.baseIP + 'zxw/company/xq/release_demand'
        }],
        badge: {
            isNeed: false
        }
    },
    '5': {
        product: [{
            fildid: '1',
            name: '我要贷款',
            href: sdk.baseIP + 'zxw/company/xq/release_demand'
        }, {
            fildid: '2',
            name: '我要担保',
            href: 'finance_product.html?jrjgtype=2'
        }],
        badge: {
            isNeed: false
        }
    },
    '88': {
        product: [{
            fildid: '4',
            name: '产品审核',
            badgeKey: 'dshcpCount',
            href: sdk.baseIP + 'zxw/jrjg/jrjgProduct/productAuditList'
        }],
        badge: {
            isNeed: true,
            requestMethod: 'post',
            href: sdk.baseIP + 'zxw/jrjg/bankDbsx/getCountNum'
        }
    },
    '990': {
        product: [{
            fildid: '6',
            name: '订单监管',
            badgeKey: '',
            href: sdk.baseIP + 'zxw/gov/app/dchsx?tname=ddxqjg'
        }, {
            fildid: '7',
            name: '统计分析',
            badgeKey: '',
            href: sdk.baseIP + 'zxw/gov/app/rzxq_zcxq?tname=qyzcxq'
        }],
        badge: {
            isNeed: false
        }
    },
    '991': {
        product: [{
            fildid: '7',
            name: '统计分析',
            badgeKey: '',
            href: sdk.baseIP + 'zxw/gov/app/rzxq_zcxq?tname=qyzcxq'
        }],
        badge: {
            isNeed: false
        }
    }
};
var statisticsUmby = {
    '0': {
        href: 'result_zhcqy.html#nature0'
    },
    '1': {
        href: 'result_zhcqy.html#nature1'
    },
    '2': {
        href: 'result_zhcqy.html#nature2'
    },
    '3': {
        href: 'result_zhcqy.html#nature3'
    }
};

//产品数据
var jgCp = {
    'bank': {
        url: 'mh/app/product/getGrid'
    },
    'warrant': {
        url: 'mh/app/v2/pro/getDbjgProductInfoList'
    },
    'insure': {
        url: 'mh/app/v2/pro/getBxjgProductInfoList'
    },
    'bond': {
        url: 'mh/app/v2/pro/getZqProductInfoViewList'
    }
}
